﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;
using System.Data;
using KPIS.Utils;
using KPIS.DBM;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.MODEL;
using Telerik.Web.UI;


namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class WF_ProjectLoan : System.Web.UI.UserControl
    {

        private object _dataItem = null;


        //ReadOnly property.
        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }
        protected bool IsUserControlPostBack
        {
            get
            {
                return this.ViewState["IsUserControlPostBack"] != null;
            }
        }



        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);

            if (!IsUserControlPostBack)
            {
                
                this.ViewState.Add("IsUserControlPostBack", true);
            }
            if (DataItem != null)
            {
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {


                    lblFinanceSeq.Text = DataBinder.Eval(DataItem, "finance_seq").ToString();
                    lblLoanSeq.Text = DataBinder.Eval(DataItem, "loan_seq").ToString();
                    txtName.Text = DataBinder.Eval(DataItem, "loan_name").ToString();
                    txtRemarks.Text = DataBinder.Eval(DataItem, "remarks").ToString();

                    this.btnAddnew.Visible = false;
                    this.btnUpdate.Visible = true;
                    this.ViewState.Add("IsUserControlPostBack", true);
                }
                else
                {
                    this.btnAddnew.Visible = true;
                    this.btnUpdate.Visible = false;
                }
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {

        }



        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            WelfareFinanceBLL obj = new WelfareFinanceBLL();


           string loan_name, remarks;
           int finance_seq;
           finance_seq = int.Parse(Session["finance_seq"].ToString());
           loan_name = txtName.Text;


           if (obj.chkDupLoan(finance_seq,loan_name) == true)
           {
               return;
           }



           remarks = txtRemarks.Text;
        


            obj.insertLoan(loan_name, finance_seq, remarks, 1);     


           
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {

            WelfareFinanceBLL obj = new WelfareFinanceBLL();

            string loan_name, remarks;
            int loan_seq,finance_seq;

            loan_name = txtName.Text;
            finance_seq = int.Parse(lblFinanceSeq.Text); 
              remarks = txtRemarks.Text;
            loan_seq = int.Parse(lblLoanSeq.Text.ToString());

            if (obj.chkDupLoanEdit(finance_seq, loan_name,loan_seq) == true)
            {
                return;
            }


          

            //lblLoanSeq.Text
            obj.UpdateLoan(loan_seq, loan_name, remarks, 1);   
           
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }





        protected void txtName_TextChanged(object sender, EventArgs e)
        {

        }

        protected void txtRemarks_TextChanged(object sender, EventArgs e)
        {

        }



    }
}